<template>
  <div class="admin-layout">
    <!-- 顶部导航栏 -->
    <el-header hei
    
    ght="60px" class="header">
      <div class="header-content">
        <div class="logo">
          <h1>短链管理后台</h1>
        </div>
        <div class="nav-right">
          <el-dropdown>
            <span class="user-info">
              <el-avatar :size="32" src="https://cube.elemecdn.com/3/7c/3ea6beec64369c2642b92c6726f1epng.png"/>
              <span class="username">管理员</span>
            </span>
            <template #dropdown>
              <el-dropdown-menu>
                <el-dropdown-item @click="$router.push('/profile')">个人中心</el-dropdown-item>
                <el-dropdown-item>系统设置</el-dropdown-item>
                <el-dropdown-item divided>退出登录</el-dropdown-item>
              </el-dropdown-menu>
            </template>
          </el-dropdown>
          <el-switch
            :model-value="isDark"
            @update:model-value="emit('update:isDark', $event)"
            active-text="暗黑"
            inactive-text="明亮"
            style="margin-left: 20px"
          />
        </div>
      </div>
    </el-header>

    <!-- 主体布局 -->
    <el-container class="main-container">
      <!-- 侧边菜单 -->
      <el-aside :width="isCollapse ? '64px' : '220px'" class="aside">
        <el-menu
          :default-active="$route.path"
          router
          :collapse="isCollapse"
          background-color="#304156"
          text-color="#bfcbd9"
          active-text-color="#409EFF">
          <el-menu-item index="/admin/links">
            <el-icon><Link /></el-icon>
            <template #title>短链管理</template>
          </el-menu-item>
          <el-menu-item index="/admin/users">
            <el-icon><User /></el-icon>
            <template #title>用户管理</template>
          </el-menu-item>
          <el-menu-item index="/admin/analytics">
            <el-icon><DataAnalysis /></el-icon>
            <template #title>数据统计</template>
          </el-menu-item>
        </el-menu>
        <div class="collapse-btn" @click="isCollapse = !isCollapse">
          <el-icon :size="20">
            <component :is="isCollapse ? 'Expand' : 'Fold'"/>
          </el-icon>
        </div>
      </el-aside>

      <!-- 主内容区 -->
      <el-main class="main-content">
        <el-card shadow="never" class="content-card">
          <router-view v-slot="{ Component }">
            <component 
              :is="Component" 
              :is-dark="isDark"
            />
          </router-view>
        </el-card>
      </el-main>
    </el-container>
  </div>
</template>

<script setup>
import { ref } from 'vue'

const props = defineProps({
  isDark: Boolean
})

const emit = defineEmits(['update:isDark'])
const isCollapse = ref(false)
</script>

<style scoped>
.admin-layout {
  height: 100vh;
  display: flex;
  flex-direction: column;
}

.header {
  background-color: var(--bg-color);
  box-shadow: 0 1px 4px rgba(0,21,41,.08);
  padding: 0;
}

.header-content {
  height: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 20px;
}

.logo h1 {
  font-size: 18px;
  color: var(--text-color);
  margin: 0;
}

.nav-right {
  display: flex;
  align-items: center;
  gap: 15px;
}

.user-info {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}

.username {
  font-size: 14px;
}

.main-container {
  flex: 1;
  overflow: hidden;
}

.aside {
  background-color: #304156;
  transition: width 0.3s;
  position: relative;
}

.el-menu {
  border-right: none;
  height: calc(100% - 48px);
}

.collapse-btn {
  height: 48px;
  display: flex;
  justify-content: center;
  align-items: center;
  background-color: #263445;
  color: #bfcbd9;
  cursor: pointer;
  transition: background-color 0.3s;
}

.collapse-btn:hover {
  background-color: #1f2d3d;
}

.main-content {
  padding: 20px;
  background-color: var(--bg-color-secondary);
}

.content-card {
  min-height: calc(100% - 20px);
  background-color: var(--card-bg);
  color: var(--text-color);
}
</style>
